package com.huobao.yunying.adapters;

import org.xutils.common.util.LogUtil;

import com.huobao.yunying.activitys.muyingquan.FristHostTiezi;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.yunying.utils.Utils;
import com.huobao.yunying.utils.ImageUtils.OnImageLoadListener;
import com.huobao.yunying.views.RoundImageView;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.utils.ScreenUtil;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_All_Tiezi extends QuickAdapter<FristHostTiezi> {

	public Adapter_All_Tiezi(Context context) {
		super(context, R.layout.item_all_tiezi);
		// TODO Auto-generated constructor stub
	}
	@Override
	protected void convert(BaseAdapterHelper arg0, final FristHostTiezi arg1) {
		RoundImageView img_userphoto = arg0.getView(R.id.img_userphoto);
		img_userphoto.setRectAdius(90);
		TextView tv_storename = arg0.getView(R.id.tv_storename);
		TextView tv_jing = arg0.getView(R.id.tv_jing);
		TextView tv_re = arg0.getView(R.id.tv_re);
		TextView tv_ding = arg0.getView(R.id.tv_ding);
		TextView tv_title = arg0.getView(R.id.tv_title);
		TextView tv_content = arg0.getView(R.id.tv_content);
		
		TextView tv_time = arg0.getView(R.id.tv_time);
		TextView tv_seenum = arg0.getView(R.id.tv_seenum);
		TextView tv_pinglun = arg0.getView(R.id.tv_pinglun);
		final ImageView img_1 = arg0.getView(R.id.img_1);
		ImageUtils.loadimg(img_userphoto, arg1.getPortrait());
		tv_storename.setText(arg1.getUser_name());
		tv_title.setText(arg1.getTitle());
		tv_content.setText(arg1.getContent());
		tv_time.setText(arg1.getCreate_time());
		tv_seenum.setText(arg1.getViews());
		tv_pinglun.setText(arg1.getComments());
		
		tv_jing.setVisibility(arg1.getIsbetter().equals("1") ? View.VISIBLE : View.GONE);
		tv_re.setVisibility(arg1.getIshot().equals("1") ? View.VISIBLE : View.GONE);
		tv_ding.setVisibility(arg1.getIsfirst().equals("1") ? View.VISIBLE : View.GONE);
		if(arg1.getImages() == null || arg1.getImages().size() == 0){
			img_1.setVisibility(View.GONE);
		}else{
			img_1.setVisibility(View.VISIBLE);
			ImageUtils.loadimg(img_1, arg1.getImages().get(0), new OnImageLoadListener() {
				@Override
				public void onLoadSuccess(Drawable drawable) {
					int []  wh = Utils.splitUrl(arg1.getImages().get(0));
					int oldWidth = wh[0];
					int oldHight = wh[1];
					int newWidth = ScreenUtil.getInstant().getDisWidth(context) - 15;
					if(oldWidth < newWidth){
						LayoutParams layoutParams = (LayoutParams) img_1.getLayoutParams();
						layoutParams.width = oldWidth;
						layoutParams.height = oldHight;
						img_1.setLayoutParams(layoutParams);
						return;
					}
					int newHight = newWidth * oldHight / oldWidth;
					LayoutParams layoutParams = (LayoutParams) img_1.getLayoutParams();
					layoutParams.width = newWidth;
					layoutParams.height = newHight;
					img_1.setLayoutParams(layoutParams);
				}
			});
		}
		
	}

}
